<?php

namespace app\index\model;

use think\Db;
use think\db\Query;
use think\facade\Request;
use think\Model;

class User extends Model{
    protected $table = 'user';
    function user(){
        $input = input();
        $a=$input['referee'];
        $validate = new \app\index\validate\User();
        if(!$validate->check($input)){
            throw new \Exception($validate->getError());
            return;
        }
        $user=Db::name('user')->where("phone",$a)->find();
        if (empty($user)) {
            throw  new \Exception("该推荐人不是商城会员！");
        }
        $data = Request::only(['name','login','password','phone','address','yue','referee','grade']);
        User::create($data);
        $u=Db::name('user')->where('login',$input['login'])->find();
        $da=['z_id'=>$user['id'],'d_id'=>$u['id']];
        Db::name('gx')->data($da)->insert();
        return;
    }
}